import type { Directive } from "vue";
import { userStore } from "../store/user";

export const permission:Directive ={
    mounted(el,binding){
        const store = userStore()
        //按钮权限字段
        const {value} = binding
        //当前用户所有权限字段
        const permissons =store.getCodeList
        if(value && value instanceof Array && value.length > 0){
            const permissionRoles = value;
            //判断按钮权限是否存在用户权限里面
            const hasPermission = permissons.some((role)=>{
                return permissionRoles.includes(role)
            })
            if(!hasPermission){
                el.style.display = 'none'
            }
        }else{
            throw new Error("按钮权限的传递方式v-permission=['sys:role:add']")
        }

    }
}